package com.zggk.lzz.sx;


import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.zggk.lzz.R;
import com.zggk.lzz.mvp.MVPBaseActivity;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * MVPPlugin
 * 邮箱 784787081@qq.com
 */

public class SxActivity extends MVPBaseActivity<SxContract.View, SxPresenter> implements SxContract.View {


    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.cancle_button)
    TextView cancleButton;
    @Bind(R.id.zqmc_et)
    EditText zqmcEt;
    @Bind(R.id.bh_te)
    TextView bhTe;
    @Bind(R.id.lz_te)
    TextView lzTe;
    @Bind(R.id.aq_te)
    TextView aqTe;
    @Bind(R.id.sh_te)
    TextView shTe;
    @Bind(R.id.zd_te)
    TextView zdTe;
    @Bind(R.id.activity_disease_new_scrollview)
    ScrollView activityDiseaseNewScrollview;
    @Bind(R.id.cz_te)
    TextView czTe;
    @Bind(R.id.qd_te)
    TextView qdTe;
    @Bind(R.id.disease_new_parent_layout)
    RelativeLayout diseaseNewParentLayout;
    @Bind(R.id.qssj_te)
    TextView qssjTe;
    @Bind(R.id.jssj_te)
    TextView jssjTe;
    private int SelInt = 0;
    private String etype="";

    @Override
    public void onRequestError(String msg) {

    }

    @Override
    protected int getLayout() {
        return R.layout.act_sx;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        initView();
        setTitleText("筛选");
        goBack();
    }

    private void initView() {
        qssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        jssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    }

    @OnClick({R.id.qssj_te, R.id.jssj_te, R.id.bh_te, R.id.lz_te, R.id.aq_te, R.id.sh_te, R.id.zd_te,
            R.id.cz_te, R.id.qd_te})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.bh_te:
                BhSelect();
                break;
            case R.id.lz_te:
                LzSelect();
                break;
            case R.id.aq_te:
                AqSelect();
                break;
            case R.id.sh_te:
                ShSelect();
                break;
            case R.id.zd_te:
                ZdSelect();
                break;
            case R.id.qssj_te:
                TimePickerView ksTimes = new TimePickerView.Builder(SxActivity.this, new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调
                        qssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(date));
                    }
                }).setType(new boolean[]{true, true, true, false, false, false})
                        .build();
                ksTimes.setDate(Calendar.getInstance());
                ksTimes.show();
                break;
            case R.id.jssj_te:
                TimePickerView jsTimes = new TimePickerView.Builder(SxActivity.this, new TimePickerView.OnTimeSelectListener() {
                    @Override
                    public void onTimeSelect(Date date, View v) {//选中事件回调
                        jssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(date));
                    }
                }).setType(new boolean[]{true, true, true, false, false, false})
                        .build();
                jsTimes.setDate(Calendar.getInstance());
                jsTimes.show();
                break;
            case R.id.cz_te:
                zqmcEt.setText("");
                CzSelect();
                qssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                jssjTe.setText(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                break;
            case R.id.qd_te:
                String orgName = zqmcEt.getText().toString();
                if (SelInt==0){
                    etype = "";
                }else if (SelInt==1){
                    etype = "病害";
                }else if (SelInt==2){
                    etype = "路政";
                }else if (SelInt==3){
                    etype = "隐患";
                }else if (SelInt==4){
                    etype = "水毁";
                }else {
                    etype = "阻断";
                }
                String startDate = qssjTe.getText().toString();
                String endDate = jssjTe.getText().toString();
                Intent intent = new Intent();
                intent.putExtra("orgName", orgName);
                intent.putExtra("etype", etype);
                intent.putExtra("startDate", startDate);
                intent.putExtra("endDate", endDate);
                setResult(2, intent);
                finish();
                break;
        }
    }

    private void BhSelect() {
        if (SelInt != 1) {
            SelInt = 1;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_bule));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
        }
    }

    private void LzSelect() {
        if (SelInt != 2) {
            SelInt = 2;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_bule));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
        }
    }

    private void AqSelect() {
        if (SelInt != 3) {
            SelInt = 3;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_bule));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
        }
    }

    private void ShSelect() {
        if (SelInt != 4) {
            SelInt = 4;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_bule));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
        }
    }

    private void ZdSelect() {
        if (SelInt != 5) {
            SelInt = 5;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_bule));
        }
    }
    private void CzSelect() {
        if (SelInt != 0) {
            SelInt = 0;
            bhTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            lzTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            aqTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            shTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
            zdTe.setBackgroundDrawable(getResources().getDrawable(R.drawable.but_back));
        }
    }
}
